package com.aaa.service.mht.impl;

import com.aaa.dao.mht.TMhtSurveyMapper;
import com.aaa.entity.MyPage;

import com.aaa.entity.mht.TMhtSurvey;
import com.aaa.service.mht.TMhtSurveyService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class TMhtSurveyServiceImpl implements TMhtSurveyService {
    @Autowired
    private TMhtSurveyMapper tMhtSurveyMapper;
    @Override
    public boolean addSurvey(TMhtSurvey tMhtSurvey) {
        int insert=-1;
        List<TMhtSurvey> select = tMhtSurveyMapper.select(tMhtSurvey);
        if (select.size()>0){
             insert = tMhtSurveyMapper.updateByPrimaryKeySelective(tMhtSurvey);
        }else {
             insert = tMhtSurveyMapper.insertSelective(tMhtSurvey);

        }
        return insert>0;
    }

    @Override
    public PageInfo querySurvey(MyPage myPage,TMhtSurvey tMhtSurvey) {
        PageHelper.startPage(myPage.getPage(),myPage.getLimit());

        return new PageInfo(tMhtSurveyMapper.selectquerySurvey(tMhtSurvey));
    }

    @Override
    public boolean updSurvey(TMhtSurvey tMhtSurvey) {
        int i = tMhtSurveyMapper.updateByPrimaryKeySelective(tMhtSurvey);
        return i>0;
    }

    @Override
    public boolean delSurvey(TMhtSurvey tMhtSurvey) {
        int i = tMhtSurveyMapper.deleteSurvey(tMhtSurvey);
        System.out.println("-------------------------------------------------------------------------");
        System.out.println(i>0);
        return i>0;
    }
}
